<%@ Page Language="C#" AutoEventWireup="true" CodeFile="manageProgram.aspx.cs" Inherits="manageProgram" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Manage TV with Program</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <table cellpadding="4" cellspacing="0" border="0">
                <tr>
                    <td colspan="2" style="font-weight: bold; text-decoration: underline;">
                        Manage TV with Program
                    </td>
                </tr>
                <tr>
                    <td>
                        TV:
                    </td>
                    <td>
                        <asp:DropDownList ID="ddlTV" runat="server" AutoPostBack="true" DataSourceID="SqlDataSource1"
                            DataTextField="vch_tv_name" DataValueField="i_tv_id" Width="160">
                        </asp:DropDownList>
                        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:uploadConnectionString %>"
                            SelectCommand="SELECT i_tv_id, vch_tv_name from tv "></asp:SqlDataSource>
                    </td>
                </tr>
            </table>
            <table cellpadding="4" cellspacing="0" border="0">
                <tr>
                    <td>
                        <table cellpadding="4" cellspacing="0" border="0" style="width: 300px; border: 1px solid black;
                            vertical-align: text-top">
                            <tr>
                                <td>
                                    Already Added Programs
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <asp:GridView ID="gvTVPrograms" AllowPaging="true" PageSize="10" runat="server" AutoGenerateColumns="False"
                                        AutoGenerateDeleteButton="True" DataKeyNames="i_program_id" DataSourceID="gridViewSqlDataSource"
                                        AutoGenerateSelectButton="true" OnRowDeleted="gvTVPrograms_RowDeleted" EmptyDataText="No Programs for the Selected TV">
                                        <Columns>
                                            <asp:BoundField DataField="vch_program_name" HeaderText="Program Name" SortExpression="vch_program_name" />
                                        </Columns>
                                        <SelectedRowStyle BackColor="AliceBlue" />
                                    </asp:GridView>
                                    <asp:SqlDataSource ID="gridViewSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:uploadConnectionString %>"
                                        SelectCommand="SELECT program.i_program_id, program.vch_program_name FROM tv_program INNER JOIN program ON program.i_program_id=tv_program.i_program_id INNER JOIN tv ON tv.i_tv_id=tv_program.i_tv_id WHERE tv_program.i_tv_id =@tv_id"
                                        DeleteCommand="DELETE FROM tv_program WHERE (i_tv_id = @tv_id) AND (i_program_id = @program_id)">
                                        <SelectParameters>
                                            <asp:ControlParameter ControlID="ddlTV" Name="tv_id" PropertyName="SelectedValue" />
                                        </SelectParameters>
                                        <DeleteParameters>
                                            <asp:ControlParameter ControlID="ddlTV" Name="tv_id" PropertyName="SelectedValue" />
                                            <asp:ControlParameter ControlID="gvTVPrograms" Name="program_id" PropertyName="SelectedValue" />
                                        </DeleteParameters>
                                    </asp:SqlDataSource>
                                </td>
                            </tr>
                        </table>
                    </td>
                    <td>
                        <table cellpadding="4" cellspacing="0" style="width: 300px; border: 1px solid black;
                            vertical-align: text-top">
                            <tr>
                                <td>
                                    Add Existing Program
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <asp:DropDownList ID="ddlProgram" runat="server" DataSourceID="programSqlDataSource"
                                        DataTextField="vch_program_name" DataValueField="i_program_id">
                                    </asp:DropDownList>
                                    <asp:RequiredFieldValidator ID="rfvProgram" runat="server" ControlToValidate="ddlProgram"
                                        ErrorMessage="* Select Program to Add" ForeColor="red"></asp:RequiredFieldValidator>
                                    <asp:SqlDataSource ID="programSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:uploadConnectionString %>"
                                        SelectCommand="SELECT i_program_id,vch_program_name FROM program WHERE i_program_id NOT IN(SELECT i_program_id FROM tv_program)">
                                    </asp:SqlDataSource>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <asp:Button runat="server" ID="btnAddProgram" Text="Add" OnClick="btnAddProgram_Click" />
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
             <asp:HyperLink ID="HyperLink1" NavigateUrl="~/tvadmin.aspx" runat="server">Go Back to Admin</asp:HyperLink>
        </div>
    </form>
</body>
</html>
